<template>
  <div class="">
    <ul>
      <h2>正在进行{{ num0 }}</h2>
      <li
        v-for="(item, index) in $store.state.todo"
        :key="index"
        v-show="item.status == 0"
      >
        <input type="checkbox" v-model="item.status" :checked="item.status" />
        <input
          type="text"
          v-model="item.title"
          v-if="flag == index"
          @blur="flag = -1"
        />
        <span @dblclick="flag = index" v-else> {{ item.title }}</span>

        <el-button size="mini" type="info" @click="remove(index)"
          >删除</el-button
        >
      </li>
    </ul>
    <ul>
      <h2>已完成{{ num1 }}</h2>
      <li
        v-for="(item, index) in $store.state.todo"
        :key="index"
        v-show="item.status == 1"
      >
        <input type="checkbox" v-model="item.status" :checked="item.status" />
        <input
          type="text"
          v-model="item.title"
          v-if="flag == index"
          @blur="flag = -1"
        />
        <span @dblclick="flag = index" v-else> {{ item.title }}</span>

        <el-button size="mini" type="info" @click="remove(index)"
          >删除</el-button
        >
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      flag: -1,
    };
  },
  mounted() {},
  methods: {
    remove(index) {
      this.$store.commit("remove", index);
    },
  },
  components: {},
  computed: {
    num0() {
      let num = this.$store.state.todo.filter((item) => {
        return item.status == 0;
      }).length;

      return num;
    },
    num1() {
      let num = this.$store.state.todo.filter((item) => {
        return item.status == 1;
      }).length;

      return num;
    },
  },
};
</script>

<style lang="scss" scoped>
ul {
  width: 800px;
  margin: 0 auto;
  li {
    background: #ccc;
    width: 800px;
    display: flex;
    height: 40px;
    margin-bottom: 20px;
    border-radius: 5px;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
